package net.yunzhanyi.client.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Writer;

/**
 * @author bestct
 * @date 2022/10/7
 * @type 类
 */
@Controller
public class SeoController {

    /**
     * robots.txt 文件
     * @param response
     */
    @GetMapping("/robots.txt")
    public void robots(HttpServletResponse response){
        String sitemapUrl = "https://www.yunzhanyi.net" + "/sitemap.xml";
        try {
            Writer writer = response.getWriter();
            String lineSeparator = System.getProperty("line.separator", "\n");
            writer.append("User-agent: *").append(lineSeparator);
            writer.append("Disallow:/api/").append(lineSeparator);
            writer.append("Disallow:/hapi/").append(lineSeparator);
            writer.append("Crawl-delay: 5").append(lineSeparator);
            writer.append("Sitemap: "+sitemapUrl);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
